package com.zhl.dom;

import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-06-10 12:26
 **/
public class HttpWebService {
	@Test
	public void web(){
		RestTemplate rest = new RestTemplate();
		String uri = "http://10.79.1.204/services/EquipQueryService?username=wlw&password=zf@123456";
		String capsule ="<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ser=\"http://service.tlm.webservice.creatsoft.com/\">   <soap:Header/>   <soap:Body> %s </soap:Body> </soap:Envelope>";

		String func = "getVessel"; //beginDate  yyyy-mm-dd
		String req = "<ser:"+func+"> <arg0> &lt;creatsoft&gt;&lt;param name=\"beginDate\" value=\"2020-06-01\" /&gt;&lt;/creatsoft&gt;</arg0> </ser:"+func+">";
//		String req = "<ser:getPipe> <arg0> &lt;creatsoft&gt;&lt;param name=\"管道编号\" value=\"TH-HF-NS-GC-0107\" /&gt;&lt;/creatsoft&gt;</arg0> </ser:getPipe>";
		String format = String.format(capsule, req);
		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
		headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON_UTF8));

		HttpEntity<String> httpEntity = new HttpEntity(format, headers);
		ResponseEntity<String> response = new RestTemplate().postForEntity(uri, httpEntity, String.class);
		System.out.println(response);
		System.out.println(format);
	}
}
